<template>
  <j-modal
    :title="title"
    :width="width"
    :height="height"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭"
    :okText='this.Text'
  >
    <div style="height: 360px">
      <a-spin :spinning="spinning">
        <div class="spin-content">


    <j-dict-select-tag  placeholder="请选择法人标识" v-show="false" v-model="model.bankNoCd" dictCode="llbb_juridical_person,BANKNAME,ID" style="width: 220px"/>
    <a-date-picker
      placeholder="请选择数据日期"
      v-model="sjrq"
      format="YYYY-MM-DD"
      style="width: 220px"
      @change="onChange"
    />
    <a-button @click="showSjrq" type="primary" style="margin-left: 9px" v-show="isShow">{{buttonName}}</a-button>
    <a-divider v-if='centralizedCalibration'/>
    <a-alert v-if='centralizedCalibration'
      message="说明:"
      description="当前日期数据会进行大集中校验!"
      type="info"
      show-icon
    />
   <!--<a-divider />
    <a-alert
      message="说明:"
      description="1.对于有大集中校验的报表,如果大集中校验有误，需填写说明，并再次点击【大集中校验】按钮，完成数据提交。
                    2.对于没有大集中校验的报表,直接选择数据日期，完成数据提交."
      type="info"
      show-icon
    />-->


    <div style="margin-top: 9px" v-show="isTableShow">
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="desStr(record)" :disabled='record.describe != null'>填写说明</a>
        </span>
      </a-table>
    </div>


    <j-modal
      :visible.sync="jmodal.visible1"
      :width="600"
      :title="jmodal.title"
      :fullscreen.sync="jmodal.fullscreen"
      :switchFullscreen="jmodal.switchFullscreen"
      @ok="handleOk1"
      @cancel="handleCancel1"
    >
      <a-button @click="copyBack" type="primary" >复制上次说明</a-button>
      <a-textarea
        v-model="jmodal.reason"
        placeholder="请输入原因"
        maxLength="2000"
        :auto-size="{ minRows: 6, maxRows: 12}"
      />
    </j-modal>
        </div>
      </a-spin>
    </div>
  </j-modal>


</template>

<script>
import { judgeSjrq } from '@/utils/util'
import { httpAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import moment from "moment";
import { getAction,putAction } from '../../../../api/manage'

export default {
  name: 'SjrqModal',
  mixins:[JeecgListMixin, mixinDevice],
  components: {
  },
  data () {
    return {
      spinning:false,
      Text:'确定',
      centralizedCalibration:false,
      loading:false,
      isShow:false,
      isTableShow:false,
      buttonName:'校验',
      jmodal: {
        title: '提交说明',
        visible1: false,
        fullscreen: false,
        switchFullscreen: false,
        ids:'',
        reason:'',
      },
      dates: [],
      reportId: "",
      dateFormat: 'YYYY-MM-DD',
      model:{
      },
      falg: true,
      tab:false,
      describeBack:undefined,
      type: '',
      sjrq: '',
      title:'请选择',
      width:900,
      height:1170,
      visible: false,
      disableSubmit: false,
      columns: [
        {
          title:'数据日期',
          align:"center",
          dataIndex: 'sjrq',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'表名',
          align:"center",
          dataIndex: 'tbname'
        },
        {
          title:'表内金额(元)',
          align:"center",
          dataIndex: 'bnje'
        },
        {
          title:'大集中金额(元)',
          align:"center",
          dataIndex: 'djzje'
        },
        {
          title:'差额(元)',
          align:"center",
          dataIndex: 'ce'
        },
        {
          title:'币种',
          align:"center",
          dataIndex: 'bz_dictText'
        },
        {
          title:'分类',
          align:"center",
          dataIndex: 'remarks'
        },
        {
          title:'说明',
          align:"center",
          dataIndex: 'describe'
        },
        {
          title:'创建人',
          align:"center",
          dataIndex: 'createBy'
        },
        {
          title:'创建时间',
          align:"center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      dataInfo:{},
      dataSource:[],
      ipagination:{
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5','10'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
      },
     url: {
        list: "/js1411Des/js1411Des/list"
      },
    }
  },
  created() {
    this.tab = false
  },
  props: {
    handleAdd: {
      type: Function,
      default: null
    }
  },
  methods: {
    copyBack(){
      this.jmodal.reason = this.describeBack
    },
    showSjrq(){
      this.centralizedCalibration= false;
      this.queryParam.sjrq=this.sjrq;
      this.queryParam.tbname=this.type.split(",")[1];
      let rq = moment(new Date().toLocaleDateString()).format("YYYY-MM-DD");
      if(this.sjrq == ''){
        this.sjrq = rq
      }
      if (!judgeSjrq(this.sjrq)){
        return;
      }
      /*if(this.model.bankNoCd == undefined || this.model.bankNoCd == ''){
        this.$message.warning("请选择法人标识")
        return
      }*/
      if(this.sjrq == undefined || this.sjrq == ''){
        this.$message.warning("请选择数据日期")
        return
      }else{
        if(this.type == "add"){
          httpAction(this.$parent.$parent.url.dataVerification,{"bankNoCd":"","sjrq":this.sjrq},'POST').then((res)=>{
            if(res.success){
              this.confirmLoading = true;
              this.confirmLoading = false;
              this.visible = false;
              this.handleAdd(this.model.bankNoCd,this.sjrq);
            }else{
              this.$message.warning(res.message)
            }
          })
        }else if(this.type.startsWith("check")){
          this.visible = false;
          this.$parent.$parent.loading = true;
          let tableCode=this.type.split(",")[1];
          this.reportId =tableCode
          httpAction("/messagemanagement/report/dataCheck",{"reportCode":tableCode,"sjrq":this.sjrq,"type":false},'POST').then((res)=>{
            if(res.success){
              this.$message.success(res.message);
              this.$emit('ok');
              this.confirmLoading = true;
              this.visible = false;
              this.$parent.$parent.loading = false;
            }else{
              this.isTableShow=true;
              this.confirmLoading = true;
              this.visible = false;
              this.$parent.$parent.loading = false;
              this.$message.warning(res.message);
            }
          })
        }else if( this.type.startsWith('校验结果表,')){
          this.$parent.$parent.handleExportXls(this.type);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='exportParticulars'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.exportParticulars(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='sync'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.sync(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='examineInfo'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.exportExamineInfo(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='createDown'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.creatDownHandle(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }
      }
    },
    handleOk1(){
      let that=this;
      that.dataInfo.describe=that.jmodal.reason;
      putAction("/js1411Des/js1411Des/edit",  that.dataInfo).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
        }else {
          that.$message.error(res.message);
          that.jmodal.visible1=true;
        }
      })
    },
    desStr(record){
      this.describeBack = record.describeBack
      this.jmodal.visible1=true;
      this.jmodal.reason=record.describe;
      this.dataInfo=record;
    },
  loadDataSource1(){
    let that=this;
    var params = {};//查询条件
    params.pageNo = this.ipagination.current;
    params.pageSize = this.ipagination.pageSize;
    params.sjrq=this.sjrq;
    params.tbname=this.type.split(",")[1];
    getAction("/js1411Des/js1411Des/list", params).then((res) => {
      if (res.success) {
        that.dataSource = res.result.records;
        if(res.result.total)
        {
          that.ipagination.total = res.result.total;
        }else{
          that.ipagination.total = 0;
        }
        this.loading = false
      }
      if(res.code===510){
        that.$message.warning(res.message)
      }
    })

  },
    openChange(){
      getAction('/customerinfo/privatecustomer/llbbPrivateCustomer/selectDates',{reportId:this.reportId}).then((res)=>{
        if(res.success){
          this.dates = res.result
        }
      })
      this.falg = false;
    },
    disabledDate(current) {
      if(this.falg){
        this.openChange();
      }
      let rq = moment(current.toLocaleString()).format("YYYY-MM-DD");
      if(this.dates.includes(rq)){
        return true;
      }else{
        return false;
      }

      return true;
    },
    onChange(date, dateString) {
      this.centralizedCalibration= false;
      this.sjrq = dateString
      if(this.type.startsWith("commit") && this.sjrq != '' && this.sjrq != undefined) {
        let tableCode = this.type.split(",")[1];
        this.reportId = tableCode
        this.centralizedCalibration= true;
        //用于大集中校验
        // if(this.isLastDay(this.sjrq)){
        getAction('/messagemanagement/llbbMessageManagement/centralizedCalibration',{reportCode:this.reportId}).then((res)=>{
            if(res.success){
              this.centralizedCalibration= true;
            }else{
              this.centralizedCalibration= false;
            }
        })
        // }
      }

    },
    moment,
    showModal(type) {
      this.centralizedCalibration= false;
      this.Text = '确定'
      //用于弹出框类型
      this.type  = type;
      this.sjrq = moment().format("YYYY-MM-DD");
      this.model = {}
      this.visible = true;
      /*this.loadDataSource1();*/
      this.isShow=false;
      this.isTableShow=false;
      this.disableSubmit = false;
      //buttonName
      if(this.type.startsWith("commit")){
        //用于大集中校验
        this.centralizedCalibration= true;
        // if(this.isLastDay(this.sjrq)){
        let vtype=this.type.split(",")[1];
          getAction('/messagemanagement/llbbMessageManagement/centralizedCalibration',{reportCode:vtype}).then((res)=>{
            if(res.success){
              this.centralizedCalibration= true;
            }else{
              this.centralizedCalibration= false;
            }
          })
        // }
        this.Text = '提交'
        this.isShow=false;
        /*this.buttonName='大集中校验';*/
      }
      /*if(this.type.startsWith("check")){
        this.isShow=true;
        this.buttonName='校验';
      }*/
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk(e) {
      let rq = moment(new Date().toLocaleDateString()).format("YYYY-MM-DD");
      if(this.sjrq == ''){
        this.sjrq = rq
      }
      if (!judgeSjrq(this.sjrq)){
        return;
      }
      /*if(this.model.bankNoCd == undefined || this.model.bankNoCd == ''){
        this.$message.warning("请选择法人标识")
        return
      }*/
      if(this.sjrq == undefined || this.sjrq == ''){
        this.$message.warning("请选择数据日期")
        return
      }else{
        if(this.type == "add"){
          httpAction(this.$parent.$parent.url.dataVerification,{"bankNoCd":"","sjrq":this.sjrq},'POST').then((res)=>{
            if(res.success){
              this.confirmLoading = true;
              this.confirmLoading = false;
              this.visible = false;
              this.handleAdd(this.model.bankNoCd,this.sjrq);
            }else{
              this.$message.warning(res.message)
            }
          })
        }else if(this.type=='sync') {
          let vdate = this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if (!vdate) {
            var a = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate = a.test(this.sjrq);
          }
          if (!vdate) {
            var da = new Date();
            var year = da.getFullYear();
            var month = da.getMonth() + 1;
            var date = da.getDate();
            this.sjrq = [year, month, date].join('-');
          }
          this.$parent.$parent.sync(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type.startsWith("handleGR")){
          let vdate = this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if (!vdate) {
            var a = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate = a.test(this.sjrq);
          }
          if (!vdate) {
            var da = new Date();
            var year = da.getFullYear();
            var month = da.getMonth() + 1;
            var date = da.getDate();
            this.sjrq = [year, month, date].join('-');
          }
          this.$parent.$parent.handleGRInfo(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type.startsWith("handleTY")){
          let vdate = this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if (!vdate) {
            var a = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate = a.test(this.sjrq);
          }
          if (!vdate) {
            var da = new Date();
            var year = da.getFullYear();
            var month = da.getMonth() + 1;
            var date = da.getDate();
            this.sjrq = [year, month, date].join('-');
          }
          this.$parent.$parent.handleTYInfo(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type.startsWith("check")){
          this.spinning = true;
          this.visible = false;
          this.$parent.$parent.loading = true;
          let tableCode=this.type.split(",")[1];
          this.reportId =tableCode
          httpAction("/messagemanagement/report/dataCheck",{"reportCode":tableCode,"sjrq":this.sjrq,"type":false},'POST').then((res)=>{
            if(res.success){
              this.spinning = false;
              this.$message.success(res.message);
              this.$emit('ok');
              this.confirmLoading = true;
              this.visible = false;
              this.$parent.$parent.loading = false;
            }else{
              this.spinning = false;
              this.isTableShow=true;
              this.confirmLoading = true;
              this.visible = false;
              this.$parent.$parent.loading = false;
              this.$confirm({
                title: "请确认",
                content: res.message,
                onOk: function () {
                }
              });
              /*this.$message.warning(res.message);*/
            }
          })
        }else if( this.type.startsWith('校验结果表,')){
          this.$parent.$parent.handleExportXls(this.type);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type.startsWith("commit")){
          this.spinning = true;
          let tableCode=this.type.split(",")[1];
          this.reportId =tableCode
          getAction('/messagemanagement/llbbMessageManagement/centralizedCalibration',{reportCode:this.reportId}).then((res)=>{
            if(res.success){
              this.centralizedCalibration= true;
            }else{
              this.centralizedCalibration= false;
            }
          })
         /* //用于大集中校验
          this.centralizedCalibration= false;
          if(this.isLastDay(this.sjrq)){

          }*/

          httpAction("/messagemanagement/report/dataCheck",{"reportCode":tableCode,"sjrq":this.sjrq,"type":true},'POST').then((res)=>{
            if(res.success){
              this.spinning = false;
              this.$message.success(res.message);
              this.confirmLoading = true;
              this.confirmLoading = false;
              this.$parent.$parent.loading = false;
              this.handleCancel()
              this.$parent.$parent.loadData(1);
            }else{
              this.spinning = false;
              let str=res.message;
              if(str.toString().indexOf("大集中")!=-1){
                this.loadDataSource1();
                this.tab = true;
                this.isTableShow=true;
              }
              this.$parent.$parent.loading = false;
              this.$message.warning(res.message);
            }
          })
          /*let tableCode=this.type.split(",")[1];
          this.reportId =tableCode
          httpAction("/messagemanagement/report/dataCheck",{"reportCode":tableCode,"sjrq":this.sjrq,"type":true},'POST').then((res)=>{
            if(res.success){
              this.$message.success(res.message);
              this.confirmLoading = true;
              this.confirmLoading = false;
              this.$parent.$parent.loading = false;
              this.$parent.$parent.loadData(1);
            }else{
              let str=res.message;
              if(str.toString().indexOf("大集中")!=-1){
                this.isTableShow=true;
              }
              this.confirmLoading = true;
              this.confirmLoading = false;
              this.visible = false;
              this.$parent.$parent.loading = false;
              this.$message.warning(res.message);
            }
          })*/
        }else if(this.type=='exportParticulars'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.exportParticulars(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='examineInfo'){
          let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
          if(!vdate){
            var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
            vdate=a.test(this.sjrq);
          }
          if(!vdate){
            var da=new Date();
            var year = da.getFullYear();
            var month = da.getMonth()+1;
            var date = da.getDate();
            this.sjrq=[year,month,date].join('-');
          }
          this.$parent.$parent.exportExamineInfo(this.sjrq);
          this.confirmLoading = true;
          this.confirmLoading = false;
          this.visible = false;
        }else if(this.type=='createDown'){
        let vdate=this.sjrq instanceof Date && !isNaN(this.sjrq.getTime());
        if(!vdate){
          var a=/^(\d{4})-(\d{1,2})-(\d{1,2})$/;
          vdate=a.test(this.sjrq);
        }
        if(!vdate){
          var da=new Date();
          var year = da.getFullYear();
          var month = da.getMonth()+1;
          var date = da.getDate();
          this.sjrq=[year,month,date].join('-');
        }
        this.$parent.$parent.creatDownHandle(this.sjrq);
        this.confirmLoading = true;
        this.confirmLoading = false;
        this.visible = false;
      }
      }
    },
    submitCallback(){
      this.tab = false;
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel () {
      this.tab= false;
      this.close()
    },
    handleCancel1 () {
      this.jmodal.visible1=false;
    },
     isLastDay(inputDate) {
      var d = new Date(inputDate.replace(/\-/, "/ "));
      var nd = new Date(d.getTime()+24*60*60*1000); //next day
      return (d.getMonth()!=nd.getMonth())

    }

  }
}
</script>